/**
 * @description 定义路由
 */

import Router from 'vue-router'
import Vue from 'vue'
import Login from '../pages/login/index.vue'
import NotFound from '../pages/NotFound'
import routes from './routes'
import interceptor  from './interceptor'


Vue.use(Router)

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new Router({
    mode:'history',
    routes:[
        {path:'/login',component:Login,meta:{nologin: true, layout: 'LoginPage'}},
        {path:'/',redirect:'/login'},
        {path:'*',component:NotFound},
        ...routes
    ]
})

//请求前拦截
router.beforeEach(interceptor)

export default router